<template>
  <div class="photo-info">
    <!-- 头部 -->
    <van-panel
      :title="imageInfo.title"
      :status="`阅读${imageInfo.click}次`"
    >
      <div class="img-box">
        <img
          v-for="(item,index) in thums"
          :key="item.id"
          v-lazy="item.src"
          alt=""
          @click="showImage(index)"
        >
      </div>
      <div>{{imageInfo.content}}</div>
    </van-panel>
    <!-- 评论 -->
    <Comment :id="id"></Comment>
  </div>
</template>
<script>
import Comment from '@/components/Comment'
import { ImagePreview } from 'vant'
export default {
  components: {
    Comment
  },
  props: ['id'],
  data() {
    return {
      imageInfo: {},
      thums: []
    }
  },
  methods: {
    async getImageInfo() {
      const res = await this.$http.getImageInfo(this.id)
      this.imageInfo = res.data.message
    },

    async getThumImages() {
      const res = await this.$http.getThumImages(this.id)
      this.thums = res.data.message
    },
    showImage(startPosition) {
      const images = []
      this.thums.forEach(item => {
        if (item.src) images.push(item.src)
      })
      ImagePreview({
        images,
        startPosition
      })
    }
  },
  created() {
    this.getImageInfo()
    this.getThumImages()
  }
}
</script>
<style lang="scss" scoped>
.photo-info {
  padding: 10px;
  .van-cell__title {
    font-size: 16px;
    font-weight: 600;
  }
  .van-panel__content {
    font-size: 12px;
    text-indent: 2em;
  }
  .img-box {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    img {
      width: 100px;
      height: 100px;
      display: block;
    }
  }
}
</style>